//
//  SYMyCenterVC.m
//  ZCJZ
//
//  Created by sujeking on 2020/3/23.
//  Copyright © 2020 jeking. All rights reserved.
//

#import "SYMyCenterVC.h"
#import <SSAppRouter/SSAppRouter.h>
@interface SYMyCenterVC ()

@end

@implementation SYMyCenterVC

- (void)viewDidLoad {
  [super viewDidLoad];
  [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
}

- (void)setupUI {
  self.navigationController.navigationBarHidden = YES;
  @try {
    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:@{}];
    self.bridge = bridge;
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                     moduleName:@"Mycenter"
                                              initialProperties:nil];
    self.view = rootView;
  } @catch (NSException *exception) {
    [self.view makeToast:exception.description duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
  } @finally {
    [self.view makeToast:@"rn 服务器没有开启" duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    NSLog(@"rn 服务器没有开启");
  }
}

@end

//*************************************************
//
//*************************************************

@interface SYMyCenterVCViewModel:NSObject<RCTBridgeModule>
@end
@interface SYMyCenterVCViewModel()
@end
@implementation SYMyCenterVCViewModel
RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(pushvc:(NSString *)vcname data:(NSDictionary *)dict) {
  dispatch_async(dispatch_get_main_queue(), ^{
    SYMyCenterVC *vc = (SYMyCenterVC *)[generalToolBox getcurrentVC];
    NSMutableDictionary *mdict = [[NSMutableDictionary alloc] initWithDictionary:dict];
    [mdict setValue:vc.bridge forKey:@"bridge"];
    [SSAppRouter pushViewControllerWithRoute:vcname type:AppRouterManagerType_Native params:mdict];
  });
}

RCT_EXPORT_METHOD(pushwebvc:(NSString *)vcname title:(NSString *)title path:(NSString *)path islocal:(BOOL)local) {
  dispatch_async(dispatch_get_main_queue(), ^{
    if (local) {
      [SSAppRouter pushViewControllerWithRoute:vcname type:AppRouterManagerType_Native params:@{@"localPath":path,@"title":title}];
    } else {
      extern NSString *baseURLStr;
      NSString *url = [NSString stringWithFormat:@"%@%@",baseURLStr,path];
      [SSAppRouter pushViewControllerWithRoute:vcname type:AppRouterManagerType_Native params:@{@"remotePath":url,@"title":title}];
    }
  });
}

RCT_EXPORT_METHOD(exit) {
  dispatch_async(dispatch_get_main_queue(), ^{
    ZCBaseUserManager *manager = [ZCBaseUserManager shareInstance];
    manager.userModel = nil;
  });
}

@end
